package servlet.admin;

import service.CommentService;
import service.Impl.CommentServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet(urlPatterns = "/admin/CommentDelete")
public class CommentDeleteServlet extends HttpServlet {
    private CommentService commentService = new CommentServiceImpl();

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("UTF-8");
        resp.setContentType("application/json;charset=UTF-8");
        Integer id = Integer.parseInt(req.getParameter("id"));
        boolean success = commentService.delete(id);
        String responseJson = "{\"success\": " + success + "}";
        resp.getWriter().write(responseJson);
    }
}
